<?php
if (!isset($website) ) { header('HTTP/1.1 404 Not Found'); die; }
$errors = "";
	function querytransform($query)
	{
		$var;
		while($row = mysql_fetch_row($query))
		{
			$var[$row[0]] [ $row[1] ] = $row[2] ;
		}
		return $var;
	}
if ( isset($_GET["search_ip"]) ) $s = safeEscape($_GET["search_ip"]); else $s=""; 
?>

<div align="center">
<h2>Buscar por ultima IP conocida</h2>
<div align="center" class="padBottom">
	 <form action="" method="get">
	 <table>
	   <tr>
	    <td width="290">
		
		  <input type="hidden" name="ip" />
		  <input style="width: 180px; height: 24px;" type="text" name="search_ip" value="<?=$s?>" />
		 <input class="menuButtons" type="submit" value="Search" />
		</td>
	   </tr>
	 </table>
	 </form>
</div>
<?php
	
	
  if ( isset($_GET["search_ip"]) AND strlen($_GET["search_ip"])>=2 ) {
  $search_ip = safeEscape( $_GET["search_ip"]);
	$sql = "SELECT A.uid, A.name, A.value
	FROM `pvpgn2_bnet` AS A INNER JOIN 
	(
		SELECT * 
		FROM `pvpgn2_bnet` 
		WHERE 	`name` = 'acct\\\\lastlogin_ip' 
		AND `value` = '$search_ip'
	) AS B 
	ON A.uid = B.uid
	WHERE 1";
  

  $result = $db->query("$sql");

  $r = $db->fetch_row($result);
  $var = querytransform($result);
?>
<div align="center">
   <table>
    <tr>
	  <th width="180" class="padLeft">Nick</th>
	  <th width="64">Email</th>
	  <th width="260">LastIP</th>
	  <th width="140">Banned</th>
	  <th width="120">Date</th>
	</tr>
   <?php
   foreach($var as $v) { 
   			$name = $v['acct\\username'];
			$mail = $v['acct\\email'];
			$lastip = $v['acct\\lastlogin_ip'];
			$banned = $v['auth\\lockk'];
			if ($banned == ""){$banned = "No";} else {$banned = "Yes";}
			$actime = $v['acct\\ctime'];
			$acctime = date("d-m-Y",$actime);?>
   <tr class="row">
     <td width="180" class="padLeft font12"><?=$name?></td>
	 <td width="64" class="font12"><?=$mail?></td>
	 <td width="260" class="overflow_hidden font12"><?=$lastip?></td>
	 <td width="140" class="font12"><?=$banned?></td>
	 <td width="120" class="font12"><i><?=$acctime?></i></td>
    </tr>
   <?php 
   }
   
   $db->free($result);
   }
?>
  </table>
</div>